<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <title>
      新引擎测试页面
    </title>
    <meta charset = "utf-8">
    <script type="text/javascript">
       //获取已安装模块列表
      function getInstalledModuleList() {
        try{
          cordova.exec(function(data){alert(data)}, errorFunc, "ModuleOperation", "getInstalledModuleList", []);
        }catch(e){alert(e)}
      }
      //获取未安装模块列表
      function getUninstallModuleList() {
        try{
          cordova.exec(function(data){alert(data)}, errorFunc, "ModuleOperation", "getUninstallModuleList", []);
        }catch(e){alert(e)}
      }

      //获取待更新模块列表
      function getUpgradeableModuleList() {
        try{
          cordova.exec(function(data){alert(data)}, errorFunc, "ModuleOperation", "getUpgradeableModuleList", []);
        }catch(e){alert(e)}
      }

      function getAllModuleList() {
        try{
          cordova.exec(function(data){alert(data);document.getElementById('info').innerHTML=data}, errorFunc, "ModuleOperation", "getAllModuleList", []);
        }catch(e){alert(e)}
      }

      //安装模块
      function installModule() {
        var identify = document.getElementById('moduleID').value;
        console.log('identify->%s',identify)
        if(!identify) return alert('empty')
        try{
          cordova.exec(function(data){alert('installModule');alert(data)}, errorFunc, "ModuleOperation", "installModule", [identify]);
        }catch(e){alert(e)}
      }

      //升级模块
      function upgradeModule() {
        var identify = document.getElementById('moduleID').value;
        console.log('identify->%s',identify)
        if(!identify) return alert('empty')
        try{
          cordova.exec(function(data){alert('upgradeModule');alert(data)}, errorFunc, "ModuleOperation", "upgradeModule", [identify]);
        }catch(e){alert(e)}
      }

      //删除模块
      function deleteModule() {
        var identify = document.getElementById('moduleID').value;
        console.log('identify->%s',identify)
        if(!identify) return alert('empty')
        try{
          cordova.exec(function(data){alert('deleteModule');alert(data)}, errorFunc, "ModuleOperation", "deleteModule", [identify]);
        }catch(e){alert(e)}
      }

      function moduleDownloadStart(identify) {
        // alert('moduleDownloadStart====>' + identify );
        document.getElementById('downloadinfo').innerHTML = 'moduleDownloadStart====>' + identify
      }

      function updateModuleProgress(identify,progress) {
        // alert('updateModuleProgress====>' + identify + 'progress===>' + progress );
        document.getElementById('downloadinfo2').innerHTML = 'updateModuleProgress====>' + identify + '<br/>progress===>' + progress
      }
      // function moduleDownloadFinish(identify) {
      //  alert("moduleDownloadFinish--->"+identify)
      // }
      // function moduleDownloadFail(identify) {
      //  alert("moduleDownloadFail--->"+identify)
      // }
      function clearInfo() {
        try{
          document.getElementById('downloadinfo2').innerHTML="";
          document.getElementById('downloadinfo').innerHTML="";
          document.getElementById('info').innerHTML="";
        }catch(e){alert(e)}
      }
      function errorFunc(err) {
        alert('err')
        alert(err)
      }
      function moduleInstallState(identify,state) {
        if(state == 'true') {
          alert("模块:" + identify + "安装成功!");
        } else {
          alert("模块:" + identify + "安装失败!");
        }
      }
      function moduleUninstallState(identify,state) {
        if(state == 'true') {
          alert("模块:" + identify + "删除成功!");
        } else {
          alert("模块:" + identify + "删除失败!");
        }
      }
      function moduleUpgradeState(identify,state) {
        if(state == 'true') {
          alert("模块:" + identify + "升级成功!");
        } else {
          alert("模块:" + identify + "升级失败!");
        }
      }
      function qid(id){
        return document.getElementById(id);
      }
      function btn1CLick(e){
        console.log(e)
        location.href = qid('address1').value
      }
       function btn2CLick(e){
        console.log(e)
        location.href = qid('address1').value+qid('address2').value
      } 
    </script>
  </head>
  <body>
    <h1>远程调试</h1>
    地址：<input id="address1" type="text" value="http://10.108.10.199:3101"><br/>
    后续：<input id="address2" type="text" value="/modules/h5-cordova-ace/pages/test2.html"><br/>
    <button id="go1" onclick="btn1CLick();">访问1</button>
    <button id="go2" onclick="btn2CLick();">访问2</button>
    <h1>exec方式接口测试</h1>
    <button id= 'getAllModuleList' onclick="getAllModuleList();">获取所有模块列表</button><br><br><br>
    <button id= 'getInstalledModuleList' onclick="getInstalledModuleList();">获取安装模块列表</button><br><br><br>
    <button id= 'getUninstallModuleList' onclick="getUninstallModuleList();">获取未安装模块列表</button><br><br><br>
    <button id= 'getUpgradeModuleList' onclick="getUpgradeableModuleList();">获取更新模块列表</button><br><br><br>
    <div id="info" style=" background-color: #ccc; min-height: 1em;"></div><br><br>
    <div id="downloadinfo" style=" background-color: #ccc; min-height: 1em;"></div><br><br>
    <div id="downloadinfo2" style=" background-color: #ccc; min-height: 1em;"></div><br><br>
    <button id='clear' onclick="clearInfo();">清数据</button><br><br>
    <input type="text" name="name" value="interface-test" id="moduleID"><br><br>
    <button id= 'installModule' onclick="installModule();">安装模块</button><br><br><br>
    <button id= 'upgradeModule' onclick="upgradeModule();">升级模块</button><br><br><br>
    <button id= 'deleteModule' onclick="deleteModule();">删除模块</button><br><br><br>
    <button style="width:150px;height:100px;text-align:center;background-color: #ccc;font-size: 3em;" onclick="history.back();">返回</button>
    <!-- <button id= 'checkAppUpdate'>检测App</button><br> -->
    <!-- <button id= 'test' onclick="test();">测试</button><br> -->
    <h1>localStorage测试</h1>

  </body>
  <script type="text/javascript" src="../../cordova.js"></script>
</html>
